package com.area.cth.mapper;

import com.area.cth.pojo.Goods;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper extends BaseMapper<Goods> {
    @Insert("insert into goods(create_user,category,title,description,price," +
            "img1,img2,img3,img4,img5,img6,img7,img8,img9,address,create_time,update_time,audit_state) " +
            "values (#{createUser},#{category},#{title},#{description},#{price}," +
            "#{img1},#{img2},#{img3},#{img4},#{img5},#{img6},#{img7},#{img8},#{img9},#{address},#{createTime},#{updateTime},#{auditState})")
    void addGoods(Goods g);

    List<Goods> getGoodsList();

    @Select("select * from goods where create_user = #{uid}")
    List<Goods> getMyGoodsList(Integer uid);

    List<Goods> searchList(String keyword);

    List<Goods> getGoodsListByCategory(Integer category);

    Goods getGoodsById(Integer id);

    @Delete("delete from goods where id=#{id}")
    void deleteGoods(Integer id);

    @Update("update goods set title=#{title},description=#{description},category=#{category}," +
            "address=#{address},price=#{price},update_time=#{updateTime} where id=#{id}")
    void update(Goods g);

    List<Goods> getGoodsByUserList(Integer userId);

    IPage<Goods> goodsList(Page<Goods> page, Integer auditState,Integer categoryId, String keyword);
}
